using System;

namespace Microsoft.SqlServer.Management.SqlManagerUI.Scripting
{
	internal abstract class ScriptHandler
	{
		private ScriptHandler successor;

		protected ScriptHandler() : this(null)
		{
		}

		protected ScriptHandler(ScriptHandler successor)
		{
			this.successor = successor;
		}

		public bool HandleScriptedEvent(ObjectScriptedEventArgs e)
		{
			if (e == null)
			{
				throw new ArgumentNullException("e");
			}
			return (this.HandleScriptedEventCore(e) && (e.Action & ScriptActions.Header) == ScriptActions.None) || (this.successor != null && this.successor.HandleScriptedEvent(e));
		}

		public void Script(ScriptWriter scriptWriter)
		{
			this.ScriptCore(scriptWriter);
			if (this.successor != null)
			{
				this.successor.Script(scriptWriter);
			}
		}

		protected abstract bool HandleScriptedEventCore(ObjectScriptedEventArgs e);

		protected abstract void ScriptCore(ScriptWriter scriptWriter);
	}
}
